package com.kuangjia.student_ems.dto;

import com.kuangjia.student_ems.entity.Department;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class DepartmentDTO {
    
    private Long id;
    private String name;
    private String description;
    private int employeeCount;
    private List<UserDTO> employees = new ArrayList<>();
    private LocalDateTime createTime;
    private LocalDateTime updateTime;
    
    public static DepartmentDTO fromEntity(Department department) {
        DepartmentDTO dto = new DepartmentDTO();
        dto.setId(department.getId());
        dto.setName(department.getName());
        dto.setDescription(department.getDescription());
        dto.setCreateTime(department.getCreateTime());
        dto.setEmployeeCount(department.getUsers().size());
        
        return dto;
    }
    
    public static DepartmentDTO fromEntityWithEmployees(Department department) {
        DepartmentDTO dto = fromEntity(department);
        dto.setEmployees(department.getUsers().stream()
                .map(UserDTO::fromEntity)
                .collect(Collectors.toList()));
        
        return dto;
    }
} 